package cn.lyjuan.android.demofive.ui.component.date_picker;

import android.app.Activity;
import android.os.Bundle;
import android.widget.DatePicker;
import android.widget.TextView;
import cn.lyjuan.android.demofive.R;

import java.util.Calendar;

/**
 * Created by chad on 2016/1/19.
 */
public class DatePickerActivity extends Activity
{
    TextView text;
    DatePicker datepicker;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        this.setContentView(R.layout.ui_date_picker);

        text = (TextView) this.findViewById(R.id.ui_date_picker_text);
        datepicker = (DatePicker) this.findViewById(R.id.ui_date_picker_picker);

        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH);
        int day = cal.get(Calendar.DAY_OF_MONTH);

        datepicker.init(year, month, day, dateChangedListener);
    }

    private DatePicker.OnDateChangedListener dateChangedListener = new DatePicker.OnDateChangedListener() {
        @Override
        public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            text.setText("时间：" + year + "-" + (monthOfYear + 1) + "-" + dayOfMonth);
        }
    };
}
